//
//  DISBproListViewController.m
//  Distributor
//
//  Created by 主事丫环 on 2019/5/9.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "DISBproListViewController.h"
#import "ASYListTableViewCell.h"
#import "DISASYListModel.h"
#import "DISBproContentViewController.h"

@interface DISBproListViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *myTableView;
@property(nonatomic,strong)NSMutableArray *mydateSource;

@end

@implementation DISBproListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    self.title = _titleStr;
    [self.leftbutton setImage:imgname(@"left_icon") forState:(UIControlStateNormal)];
    
    self.mydateSource = [NSMutableArray arrayWithCapacity:1];
    [self.myTableView reloadData];
    
    // Do any additional setup after loading the view.
    [self request];
    [self showheader];
}
-(void)showheader{
    UIView *head = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, 69)];
    head.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
    UILabel *contertLb = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, KWIDTH, 37)];
    contertLb.textAlignment = NSTextAlignmentCenter;
    contertLb.textColor = zhutiColor;
    contertLb.font = FontSize(26);
    contertLb.text = [NSString stringWithFormat:@"%@(元)",_moneyStr];
    [head addSubview:contertLb];
    self.myTableView.tableHeaderView = head;
    
    
    
    
}

-(void)request{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithCapacity:1];
    param[@"type"] = _typeSYstr;
    [NetWorkTool POST:getSYapi param:param success:^(id dic) {
        [self.mydateSource removeAllObjects];
                
        for (NSMutableDictionary *mudic in [[dic objectForKey:@"data"] objectForKey:@"list"]) {
            [DYModelMaker DY_makeModelWithDictionary:mudic modelKeyword:@"" modelName:@""];
            DISASYListModel *model = [[DISASYListModel alloc]init];
            [model setValuesForKeysWithDictionary:mudic];
            [self.mydateSource addObject:model];
        }
        [self.myTableView reloadData];
    } other:^(id dic) {
        ShowToastWithText(dic[@"msg"]);
        [self.mydateSource removeAllObjects];
        [self.myTableView reloadData];
        
    } fail:^(NSError *error) {
        [self.mydateSource removeAllObjects];
        [self.myTableView reloadData];
        
    } needUser:YES];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.mydateSource.count;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    return [UIView new];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 75;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ASYListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASYListTableViewCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    DISASYListModel *model = _mydateSource[indexPath.section];
    [cell reashmodel:model];
    if ([model.icet_id integerValue] == 1) {
        cell.bgLB.backgroundColor = [UIColor colorWithHexString:@"#B1B0AF"];
    }else{
        cell.bgLB.backgroundColor = [UIColor whiteColor];
        
        
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    DISASYListModel *model = _mydateSource[indexPath.section];
    
    DISBproContentViewController *VC= [[DISBproContentViewController alloc]init];
    
    VC.urls = model.Id;
    [self.navigationController pushViewController:VC animated:YES];
}


-(UITableView *)myTableView{
    if (!_myTableView) {
        _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, kNaviHeight, KWIDTH, KHEIGHT-kNaviHeight) style:(UITableViewStylePlain)];
        _myTableView.backgroundColor = [UIColor clearColor];
        _myTableView.delegate = self;
        _myTableView.dataSource = self;
        _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        _myTableView.estimatedRowHeight = 90;
        _myTableView.rowHeight = UITableViewAutomaticDimension;
        _myTableView.tableFooterView = [UIView new];
        [_myTableView registerNib:[UINib nibWithNibName:@"ASYListTableViewCell" bundle:nil] forCellReuseIdentifier:@"ASYListTableViewCell"];
        adjustInset(_myTableView);
        [self.view addSubview:_myTableView];
    }
    return _myTableView;
}

@end
